<?php

namespace App\Http\Middleware;

use Closure;

class CheckLogin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $current_url = $request->getRequestUri(); //当前url
        $user_info = session('user_info');
        $not_need_login = config('constant.not_need_login');
        if(!in_array($current_url , $not_need_login) && !$user_info){
            return redirect('/login/index');
        }
        if($user_info && $current_url=='/login/index'){
            return redirect('/index/index');
        }
        return $next($request);
    }
}
